import { getFDAbnormal, getFSAbnormal, getQpzs, getMainReport } from '@/services/warning';
import { getDetail } from '@/services/api';

export default {
  namespace: 'opwarning',

  state: {
    FDAbnormalData: {},
    FSAbnormalData: {},
    QpzsData: {},
    MajorFormData: {},
    detailInfo: {},
  },

  effects: {
    *getFDAbnormalData({ payload }, { call, put }) {
      const response = yield call(getFDAbnormal, payload);
      yield put({
        type: 'setFDAbnormal',
        payload: {
          FDAbnormalData: response,
        },
      });
    },
    *getFSAbnormalData({ payload }, { call, put }) {
      const response = yield call(getFSAbnormal, payload);
      yield put({
        type: 'setFSAbnormal',
        payload: {
          FSAbnormalData: response,
        },
      });
    },
    *getQpzsData({ payload }, { call, put }) {
      const response = yield call(getQpzs, payload);
      yield put({
        type: 'setQpzs',
        payload: {
          QpzsData: response,
        },
      });
    },
    *getMainReport({ payload }, { call, put }) {
      const response = yield call(getMainReport, payload);
      yield put({
        type: 'setMainReport',
        payload: {
          MajorFormData: response,
        },
      });
    },
    *getDetailInfo({ payload }, { call, put }) {
      try {
        const response = yield call(getDetail, payload);
        yield put({
          type: 'setDetailInfo',
          payload: {
            detailInfo: response,
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
  },
  reducers: {
    setFDAbnormal(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setFSAbnormal(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setQpzs(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setMainReport(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setDetailInfo(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
